package com.tyl.lock;

import lombok.SneakyThrows;

import java.util.concurrent.TimeUnit;

public class SpinLockTest {
    @SneakyThrows
    public static void main(String[] args) {
        SpinLockDemo task=new SpinLockDemo();

        new Thread(()->{
            task.myLock();
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                task.myUnLock();
            }
        },"T1").start();


        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            task.myLock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                task.myUnLock();
            }
        },"T2").start();
    }
}
